import React from 'react';
import { Tag, Button } from 'antd';
import moment from 'moment';

const tableSources = [
    {
        title: 'Vue',
        createTime: moment().format('YYYY-MM-DD HH:mm:ss'),
        star: ((1 + Math.random()) * 10000).toFixed(),
        message: '渐进式 JavaScript 框架',
        github: 'https://github.com/vuejs/vue'
    },
    {
        title: 'React',
        createTime: moment().format('YYYY-MM-DD HH:mm:ss'),
        star: ((1 + Math.random()) * 10000).toFixed(),
        message: '创建大型的 JavaScript 应用程序',
        github: 'https://github.com/facebook/react'
    },
    {
        title: 'Node',
        createTime: moment().format('YYYY-MM-DD HH:mm:ss'),
        star: ((1 + Math.random()) * 10000).toFixed(),
        message: '基于 V8 引擎的 JS 运行环境',
        github: 'https://github.com/nodejs/node'
    },
    {
        title: 'Webpack',
        createTime: moment().format('YYYY-MM-DD HH:mm:ss'),
        star: ((1 + Math.random()) * 10000).toFixed(),
        message: '用于现代 JavaScript 应用程序的静态模块打包工具',
        github: 'https://github.com/webpack/webpack'
    }
];
const tableColumns = [
    {
        title: '项目名称',
        dataIndex: 'title'
    },
    {
        title: '描述',
        dataIndex: 'message'
    },
    {
        title: '创建时间',
        dataIndex: 'createTime',
        align: 'center'
    },
    {
        title: 'Star 数',
        dataIndex: 'star',
        align: 'center'
    },
    {
        title: '操作',
        dataIndex: 'cz',
        align: 'center',
        render: (text, record) => {
            return (
                <div>
                    <Tag color="green">NICE</Tag>
                    <Tag color="#2db7f5">编辑</Tag>
                    <Tag
                        color="#87d068"
                        onClick={() => window.open(record.github)}
                    >
                        传送
                    </Tag>
                </div>
            );
        }
    }
];

let newTableSources = [];
let newTableColumns = [];
for (let i = 0; i < 20; i++) {
    newTableSources.push(...tableSources);
}
newTableColumns = tableColumns.map(item => {
    item.key = item.dataIndex;
    return item;
});

export default {
    namespace: 'tables',

    state: {
        tableSources: newTableSources,
        tableColumns: newTableColumns
    },

    effects: {},

    reducers: {}
};
